<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

	</head>
	<body>
		<script type="text/javascript">
			//创建一个DIV新元素
			var div = document.createElement("div");
			div.style.color = "red";
			div.style.fontSize = "80px";
			div.style.fontWeight = "bold";
			div.style.width = "200px";
			div.style.height = "100px"
			div.style.background = "pink";
			div.style.margin = "0px auto";
			div.style.textAlign = "center";
			div.style.lineHeight = "100px";
			//获取body元素
			// document.writeln(document.getElementsByTagName("body").length)
			var body = document.getElementsByTagName("body")[0];
			//把新创建好的div元素追加到body里面
			body.append(div);

			function show() {
				// Math.random() * (最大值 - 最小值 + 1) + 最小值
				// document.write(luck);
				var luck = parseInt(Math.random() * (10 - 1 + 1) + 1);
				div.innerText = luck;
			}


			var oTimer = setInterval("show()", 10);

			function btnStop() {
				var btn = document.getElementById("btnStop");
				if (btn.innerText === "停止") {
					btn.innerText = "开始";
					clearInterval(oTimer);
				} else {
					btn.innerText = "停止";
					oTimer = setInterval("show()", 10);
				}
			}
		</script>
		<button id="btnStop" onclick="btnStop()"
			style="width: 100px;height: 50px;border-radius: 50px;border: none;background: #111;color: #fff;position: relative;top: 20px;left:40%;">停止</button>
	</body>

</html>
